<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 200px;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        #ipt {
            margin-right: 10px;
        }
        .list2 {
            border: 1px solid black;
            list-style: none;
            padding-left: 0;
        }
        .list2 li {
            width: 50px;
            border-bottom: 1px solid black;
        }
    </style>
</head>
<body>
    <div class="box">
        <div class="wenben">
            <input type="text" value="被拖动元素" id="ipt">
        </div>
        <ul class="list2">
            <li>4</li>
            <li>5</li>
            <li>6</li>
        </ul>
    </div>
    <script>
        // 把list2改变成允许拖动的目标
        let droptarget = document.querySelector('.list2')
        droptarget.addEventListener('dragenter', (event) => {
            // console.log(event, 'dragenter');
            // console.log(event.dataTransfer.getData(''), 'event.dataTransfer.getData()');
            
            event.preventDefault()
        })
        droptarget.addEventListener('dragover', (event) => {
            // console.log(event, 'dragover');
            // console.log(event.dataTransfer.getData('name'), 'event.dataTransfer.getData');
            event.preventDefault()
        })
        droptarget.addEventListener('drop', (event) => {
            // dragleave拿不到数据，但是drop能够拿到
            console.log('drop 拿值', event.dataTransfer.getData('name'));
        })

        // 拿到ipt元素
        let ipt = document.querySelector('#ipt')
        ipt.addEventListener('dragstart', (event) => {
            console.log('dragstart存值', ipt.value);
            event.dataTransfer.setData('name', ipt.value)
        })
    </script>
</body>
</html>